<?PHP
  $current_page = "view_event.php";
  $page_type = "";
  require_once 'header.php';
?>
	<div id="page">
	  <div id="page-padding">
        <!-- start content -->	    
	    <div id="content">
	      <div id="content-padding">
            <h1>Current Events</h1>
            
			<!-- Generate table of events -->
			
			
			<?PHP
			
			 if(!empty($_GET["signup_error"])) {
			    $msg = "<font color=\"#CC0000\">{$_GET["signup_error"]}</font>";
			  } else {
			    $msg = '';
			  }
			//Form to search for an event
				echo("<p><br><b>Search:</b><fieldset><form method=\"post\" action=\"view_event.php\"><br>
				Event Stakeholder ID: <input type=\"text\" size=\"20\" maxlength=\"30\" name=\"input_sid\"> 
				Event ID: <input type=\"text\" size=\"20\" maxlength=\"8\" name=\"input_eid\">
				Event Name: <input type=\"text\" size=\"20\" maxlength=\"50\" name=\"input_ename\"> <br><br />
				Location Name: <input type=\"text\" size=\"20\" maxlength=\"50\" name=\"input_lcname\"> <br> <br />
				Street: <input type=\"text\" size=\"20\" maxlength=\"50\" name=\"input_street\"> 
				City: <input type=\"text\" size=\"20\" maxlength=\"50\" name=\"input_city\"> 
				State: <input type=\"text\"  size=\"20\" maxlength=\"50\" name=\"input_state\">
				Zip: <input type=\"text\" size=\"12\" maxlength=\"12\" name=\"input_zip\">
				<input type=\"submit\" name=\"search\" value=\"Search\">&nbsp&nbsp$msg<br>
				<br></form></fieldset></p><br>");
				
				if (isset($_POST["input_sid"]))
					$input_sid = $_POST["input_sid"];
				if (isset($_POST["input_eid"]))
					$input_eid = $_POST["input_eid"];
				if (isset($_POST["input_ename"]))
					$input_ename = $_POST["input_ename"];
				if (isset($_POST["input_lcname"]))
					$input_lcname = $_POST["input_lcname"];
				if (isset($_POST["input_street"]))
					$input_street = $_POST["input_street"];
				if (isset($_POST["input_city"]))
					$input_city = $_POST["input_city"];
				if (isset($_POST["input_state"]))
					$input_state = $_POST["input_state"];
				if (isset($_POST["input_zip"]))
					$input_zip = $_POST["input_zip"];
					
				$whereclause = "1=1 ";

				if (isset($input_sid) and trim($input_sid) != "")
					$whereclause .= " and userid like '%$input_sid%'";
				if (isset($input_eid) and trim($input_eid) != "")
					$whereclause .= " and eventid like '%$input_eid%'";
				if (isset($input_ename) and trim($input_ename) != "")
					$whereclause .= " and ename like '%$input_ename%'";
				if (isset($input_lcname) and trim($input_lcname) != "")
					$whereclause .= " and lcname like '%$input_lcname%'";
				if (isset($input_street) and trim($input_street) != "")
					$whereclause .= " and street like '%$input_street%'";
				if (isset($input_city) and trim($input_city) != "")
					$whereclause .= " and city like '%$input_city%'";
				if (isset($input_state) and trim($input_state) != "")
					$whereclause .= " and state like '%$input_state%'";
				if (isset ($input_zip) and trim($input_zip) != "")
					$whereclause .= " and zip like '$input_zip'";
				
				
				echo("<form method=\"post\" action=\"view_event_response.php\"> <table border = 1><tr>");
			  if(isset($_SESSION['vflag']) and $_SESSION['vflag'] == "y")
			    echo("<th>&nbsp;</th>");
			  echo("<th>ID</th><th>Name</th><th>Location</th><th>Start Time</th><th>End Time</th><th>Description</th></tr>");
			
			 
			
			//Generate the SQL query for the table of events
			  $sql = "select EventID, Ename, LCName, Street, City, State, Zip, S_Time, E_Time, Description from Event where $whereclause order by EventID";
			  $result_array = execute_sql_in_oracle($sql);
			  $result = $result_array["flag"];
			  $cursor = $result_array["cursor"];
			  if(!$result){
			    display_oracle_error_message($cursor);
				die("Event query failed.");
			  }
			  while($values = oci_fetch_array($cursor)){
			    $t_eid = $values[0];
				$t_ename = $values[1];
				$t_lcname = $values[2];
				$t_street = $values[3];
				$t_city = $values[4];
				$t_state = $values[5];
				$t_zip = $values[6];
				$t_stime = $values[7];
				$t_etime = $values[8];
				$t_desc = $values[9];
				
				$t_location = "";
				if(!empty($t_lcname) and $t_lcname != "")
				  $t_location = $t_lcname . ", ";
				if(!empty($t_street) and $t_street != "")
				  $t_location = $t_location . $t_street;
				if(!empty($t_city) and $t_city != "")
				  $t_location = $t_location .", ". $t_city;
				if(!empty($t_state) and $t_state != "")
				  $t_location = $t_location .", " . $t_state;
				if(!empty($t_zip) and $t_zip != "")
				  $t_location = $t_location ." ". $t_zip;
				  
				$t_sdate = "";
				$t_edate = "";
				//Generate the 'D d-M-y' format for start and end time
				if(isset($t_stime) and $t_stime != "") 
				  $t_sdate = date('D d-M-y', strtotime($t_stime));
				if(isset($t_etime) and $t_stime != "")
				  $t_edate = date('D d-M-y', strtotime($t_etime));
				
				echo("<tr>");
				if(isset($_SESSION['vflag']) and $_SESSION['vflag'] == "y")
				  echo("<td><input type=\"checkbox\" name=\"input_signup[]\" value=\"$t_eid\"></td>");
				echo("<td>$t_eid</td><td>$t_ename</td><td>$t_location</td><td>$t_sdate</td><td>$t_edate</td><td>$t_desc</td></tr>");
			  }
			  echo("</table>");
			  if(isset($_SESSION['vflag']) and $_SESSION['vflag'] == "y")
			    echo("<br><input type=\"submit\" value=\"Sign Up\">&nbsp&nbsp$msg");
			  echo("</form>");
			  oci_free_statement($cursor);
			  
			?>
			
	      </div>
		</div>
	  <!-- end content --></div>
	  <div id="footer">
	    <div id="footer-pad">
	      <div class="line"></div>
		  <!-- footer and copyright notice -->
	      <p>Design by <a href="http://www.steves-templates.com">Steve's free website templates</a>.</p>
		  <!-- end footer and copyright notice -->
	    </div>
	  </div>
	</div>
  </body>
</html>